package cn.itcast.n3_Java线程;

import lombok.extern.slf4j.Slf4j;

/**
 * @program: juc
 * @description:
 * @author: flyduck
 * @create: 2024-08-28 15:17
 **/
@Slf4j(topic = "c.Test09_sleep方法_使用interrupt打断正在sleep的线程")
public class Test09_sleep方法_使用interrupt打断正在sleep的线程 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread("t1"){
            @Override
            public void run() {
                log.debug("enter sleep...");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    log.debug("wake up...");
                    e.printStackTrace();
                }
            }
        };
        t1.start();
        Thread.sleep(1000);
        log.debug("interrupt...");
        t1.interrupt();

    }

}
